#!/usr/bin/env node

const http = require('http'),
      log  = console.log,
      fs   = require('fs')

http.createServer((req, res) => {
  log(`${req.method} ${req.url} HTTP/${req.httpVersion}`)
  let file = require('path').join(__dirname, req.url)

  if (fs.existsSync(file)) {
    fs.createReadStream(file).pipe(res)
  } else {
    res.statusCode = 404
    res.end(req.url + 'not exist!')
  }
}).listen(8080)

